import {Component, OnInit} from '@angular/core';
import {Router} from "@angular/router";
import {CertificateItem} from "../../modals/basic.modal";
import {BasicService} from "../../unit/basic-service";

@Component({
    selector: 'app-certificate-list',
    templateUrl: './certificate-list.page.html',
    styleUrls: ['./certificate-list.page.scss'],
})
export class CertificateListPage implements OnInit {
    certificateList: Array<CertificateItem>;

    constructor(private route: Router,
                private basicService: BasicService) {
    }

    ngOnInit() {
        this.initData();

    }

    initData(){
        this.basicService.getData('zgzs/dzmzmc').subscribe(res=>{
            this.reGroupList(res);
        })
    }

    reGroupList(list) {
        this.certificateList = [...list];
        const newList = [];
        this.certificateList.map((item, index) => {
            const cData = {
                icon: item.type === 1 ? './assets/image/temporary/qualification-certificate-img.jpeg'
                    : './assets/image/temporary/practice-certificate-img.jpeg',
                bgColor: item.certificateName === '资格证书'? '#DDF5F7' :
                    item.certificateName === '执业证书' ? '#DDE4F7' : '#DDF7EF',
                url: './assets/image/temporary/certificate-img.png',
            };
            newList.push({...item, ...cData})
        });
        this.certificateList = [...newList];
    }

    goToPage(url, item = {}) {
        this.route.navigate([`/${url}`], {queryParams: {...item}}).then();
    }
}
